let uu = document.querySelector('#product>ul')
let el = ""
fetch('http://chst.vip:1234/api/getinlanddiscount')
    .then(body => body.json())
    .then(res => {
        console.log(res)
        res.result.forEach(item => {
            console.log(item)
            el += `<li productid=${item.productId}>
            <a>
            ${item.productImg}
            <p class="title">${item.productName}</p>
            <p class="price">${item.productPrice}</p>
            <p class="from">${item.productFrom}</p>
            </a>
            </li>`
        })
        uu.innerHTML = el
    })

// uu.onclick = function (e) {
//     if (_this.localName === "li") {
//         let id = _this.getAttribute('productid')
//         console.log(id);
//         location.href = "./indexXiang.html"
//     }
// }
// let lis = document.querySelectorAll('#product>ul>li')
// for (var i = 0; i < lis.length; i++) {
//     lis[i].onclick = function () {
//         let id = this.getAttribute('productid')
//         location.href = './inlandDetail.html'
//     }
// }

uu.onclick = e => {
    let _this = e.target;
    if (_this.localName === "li") {
        let id = _this.getAttribute('productid')
        console.log(id);
        location.href = "./inlandDetail.html?productid=" + id
    } else if (_this.localName === "a" ) {
        let id = _this.parentNode.getAttribute('productid')
        console.log(id);
        location.href = "./inlandDetail.html?productid=" + id
    } else if (_this.localName === "p"|| _this.localName === "img") {
        let id = _this.parentNode.parentNode.getAttribute('productid')
        location.href = "./inlandDetail.html?productid=" + id
        console.log(id);

    }
}
